From 67367a65f1408d2fe645a915e60e25a4da215f96 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Jul 2016 20:33:57 +0300 Subject: [PATCH] Remove now unnecessary Rustc::blank method --- src/cargo/util/rustc.rs | 34 +++++++++++++++++----------------- tests/version.rs | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/cargo/util/rustc.rs b/src/cargo/util/rustc.rs index aedf6e19c..51039de7a 100644 --- a/src/cargo/util/rustc.rs +++ b/src/cargo/util/rustc.rs @@ -5,11 +5,12 @@ use util::{self, CargoResult, internal, ChainError}; pub struct Rustc { pub verbose_version: String, pub host: String, + /// Backwards compatibility: does this compiler support `--cap-lints` flag? pub cap_lints: bool, } impl Rustc { - /// Run the compiler at `path` to learn varioues pieces of information about + /// Run the compiler at `path` to learn various pieces of information about /// it. /// /// If successful this function returns a description of the compiler along @@ -18,33 +19,32 @@ impl Rustc { let mut cmd = util::process(path.as_ref()); cmd.arg("-vV"); - let mut ret = Rustc::blank(); let mut first = cmd.clone(); first.arg("--cap-lints").arg("allow"); - let output = match first.exec_with_output() { - Ok(output) => { ret.cap_lints = true; output } - Err(..) => try!(cmd.exec_with_output()), + + let (cap_lints, output) = match first.exec_with_output() { + Ok(output) => (true, output), + Err(..) => (false, try!(cmd.exec_with_output())), }; - ret.verbose_version = try!(String::from_utf8(output.stdout).map_err(|_| { + + let verbose_version = try!(String::from_utf8(output.stdout).map_err(|_| { internal("rustc -v didn't return utf8 output") })); - ret.host = { - let triple = ret.verbose_version.lines().filter(|l| { + + let host = { + let triple = verbose_version.lines().find(|l| { l.starts_with("host: ") - }).map(|l| &l[6..]).next(); + }).map(|l| &l[6..]); let triple = try!(triple.chain_error(|| { internal("rustc -v didn't have a line for `host:`") })); triple.to_string() }; - Ok(ret) - } - pub fn blank() -> Rustc { - Rustc { - verbose_version: String::new(), - host: String::new(), - cap_lints: false, - } + Ok(Rustc { + verbose_version: verbose_version, + host: host, + cap_lints: cap_lints, + }) } } diff --git a/tests/version.rs b/tests/version.rs index f15f1e2cd..bc1040ed1 100644 --- a/tests/version.rs +++ b/tests/version.rs @@ -55,4 +55,4 @@ fn version_works_without_rustc() { let p = project("foo"); assert_that(p.cargo_process("version").env("PATH", ""), execs().with_status(0)); -} \ No newline at end of file +} -- 2.30.2